package br.com.mural.android.adaptadores;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.com.mural.android.R;
import br.com.mural.android.entidades.Turma;

public class TurmaAdapter extends BaseAdapter{
	private LayoutInflater inflater;
	private List<Turma> turmas;
	
	public TurmaAdapter(Context context, List<Turma> turmas) {
        this.turmas = turmas;
        inflater = LayoutInflater.from(context);
    }

	@Override
	public int getCount() {
		return turmas.size();
	}

	@Override
	public Object getItem(int position) {
		return turmas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ItemSuporte itemHolder;
		
        if (view == null) {
            view = inflater.inflate(R.layout.item_turma, null);

            itemHolder = new ItemSuporte();
            itemHolder.txtDisciplina = ((TextView) view.findViewById(R.id.disciplina));
            itemHolder.txtAnoSemestre = ((TextView) view.findViewById(R.id.anoSemestre));;
            itemHolder.txtProfessor = ((TextView) view.findViewById(R.id.professor));
 
            view.setTag(itemHolder);
        } else {

            itemHolder = (ItemSuporte) view.getTag();
        }
 

        Turma item = turmas.get(position);

        itemHolder.txtDisciplina.setText(item.getDisciplina());
        itemHolder.txtAnoSemestre.setText(item.getAno()+" - "+ item.getSemestre());
        itemHolder.txtProfessor.setText(item.getProfessor().getNome());
        
        if(position % 2 == 0){
        	view.setBackgroundColor(Color.GRAY);
        }else{
        	view.setBackgroundColor(Color.LTGRAY);
        }
        return view;
	}
	
	private class ItemSuporte {
        TextView txtDisciplina;
        TextView txtAnoSemestre;
        TextView txtProfessor;
    }

}
